package debut.peinture;

import java.util.ArrayList;
import java.util.List;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Typeface;
import android.graphics.drawable.BitmapDrawable;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

public class CategorieAdapter extends BaseAdapter {
	private Context monContexteAdapt;
	private List<CategorieDonnees> mesItems = new ArrayList<CategorieDonnees>();
	
	public CategorieAdapter(Context contexte) {
    	monContexteAdapt = contexte;
    }
	
	public void addItem(CategorieDonnees item) {
		mesItems.add(item);
    	}
	
	public void delItem(int position) {
		mesItems.remove(position);
    	}

	@Override
	public int getCount() {
		return mesItems.size();
	}

	@Override
	public Object getItem(int position) {
		return mesItems.get(position);
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		TextView btv;
		if (convertView != null) {
			btv = (TextView) convertView;
		} else {
			btv = new TextView(monContexteAdapt);
		}
		btv.setText(mesItems.get(position).getPhrase());
		btv.setTextSize((float)mesItems.get(position).getTaille());
		btv.setTypeface(Typeface.DEFAULT, Typeface.BOLD);
		btv.setPadding(mesItems.get(position).getMarge(), 0, 0, 0);
//		btv.setTextColor(android.R.color.white);
		btv.setMaxLines(2);
		Bitmap img = BitmapFactory.decodeResource(monContexteAdapt.getResources(), mesItems.get(position).getRessource());
		BitmapDrawable imgdraw = new BitmapDrawable(monContexteAdapt.getResources(),img);
		btv.setCompoundDrawablesWithIntrinsicBounds(null,null,imgdraw,null);
		btv.setCompoundDrawablePadding(10);
		return btv;
	}

}
